package com.xujiang.myblog.tools;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;

import com.wang.avi.AVLoadingIndicatorView;
import com.xujiang.myblog.R;
import com.xujiang.myblog.util.UIUtils;

/**
 * Created by xujiang on 2017/4/19.
 */

public class CPProgressHelper {
    public AVLoadingIndicatorView getmProgressBar() {
        return mProgressBar;
    }

    public void setmProgressBar(AVLoadingIndicatorView mProgressBar) {
        this.mProgressBar = mProgressBar;
    }

    public View getmLayout() {
        return mLayout;
    }

    public void setmLayout(View mLayout) {
        this.mLayout = mLayout;
    }

    private AVLoadingIndicatorView mProgressBar;
    private View mLayout;

    public static CPProgressHelper with(View view){
        View layout = view.findViewById(R.id.ek_cp_progress_layout);
        return new CPProgressHelper(layout,(AVLoadingIndicatorView) UIUtils.findViewById(view,R.id.ek_cp_progress));
    }

    public static CPProgressHelper with(@NonNull Activity activity) {
        View layout = activity.findViewById(R.id.ek_cp_progress_layout);
        AVLoadingIndicatorView viewById = (AVLoadingIndicatorView) UIUtils.findViewById(activity, R.id.ek_cp_progress);
        return new CPProgressHelper(layout,viewById);
    }

    public CPProgressHelper(AVLoadingIndicatorView progressBar) {
        mProgressBar = progressBar;
    }

    private CPProgressHelper(View layout, AVLoadingIndicatorView progressBar) {
        mLayout = layout;
        mProgressBar = progressBar;
    }

    public void visible(){
        mProgressBar.show();
        if(mLayout != null){
            UIUtils.viewVisible(mLayout);
        }
    }

    public void gone(){
        mProgressBar.hide();
        if(mLayout != null){
            UIUtils.viewGone(mLayout);
        }
    }


}
